﻿/*CLR Version: 4.0.30319.18063
 * Creat Date: 2015/1/27 10:26:02
 * Creat Year: 2015
 * Creator: 程炜.Snail
 */
using System;
using System.Collections.Generic;
using System.Linq;

namespace Utility.Extensions
{
    public static class BooleanExtensions
    {
        /// <summary>
        /// bool 值的扩展方法
        /// 生成含属性 [bool]Result,[string]Msg,[string]OtherInfo 的 对象
        /// </summary>
        /// <param name="bl"></param>
        /// <param name="trueMsg">当值为True时的Msg值</param>
        /// <param name="falseMsg">当值为False时的Msg值,如果不设置falseMsg,将默认使用trueMsg</param>
        /// <param name="otherInfo">其它信息</param>
        /// <param name="otherValue">其它值</param>
        /// <returns></returns>
        public static object ToJsonObject(this bool bl, string trueMsg = "", string falseMsg = "", string otherInfo = "", string otherValue = "")
        {
            var obj = new
            {
                Result = bl,
                Msg = string.IsNullOrEmpty(falseMsg) ? trueMsg : (bl ? trueMsg : falseMsg),
                OtherInfo = otherInfo,
                OtherValue = otherValue
            };
            return obj;
        }
    }
}